home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-09-28 | 6.3 KB | 192 lines |
- '***************************
- '* AMOS Professional *
- '* *
- '* AMAL_2 * Amal Registers
- '* *
- '* (c) Europress Software *
- '* *
- '* Ronnie Simpson *
- '***************************
- '
- '-------------------------------------------
- 'Internal registers
- '-------------------------------------------
- 'Each Amal channel has its own set of internal registers which operate like
- 'local variables and can hold values in the range of -32768 to 32767.
- 'There are 10 for each channel named R0-R9 and these can hold different
- 'values in each amal program.
- '-------------------------------------------
- 'The Amal Let instruction
- '-------------------------------------------
- 'keyword L
- '
- 'Values are assigned to the amal registers with the Amal Let or L in a
- 'similar manner to normal basic variables.
- '
- 'eg. Let R0=200 Let R2=R0 LR3=R3+1
- '
- '-------------------------------------------
- 'External registers
- '-------------------------------------------
- 'In addition to the internal registers R0-R9 which are local to each Amal
- 'program there is also a set of registers for holding values which are common
- 'to all Amal programs and allow values to be shared between them. These
- 'registers are accessed with the letter R being followed this time by a
- 'second letter A-Z giving a total of 26 external registers RA-RZ.
- '
- 'eg. Let RA=100 Let RA=R0 LRX=RX+1
- '
- '-------------------------------------------
- 'The Amal For To Next loop
- '-------------------------------------------
- 'Keywords F T N
- '
- 'This is the Amal version of the basic For...Next loop which can be used in
- 'conjunction with both the internal and external registers. Unlike normal
- 'Basic the step size can not be changed and is always set to 1.
- 'One step of the loop will be performed per vertical blank (1/50th. of a
- 'second) and the appropriate register name must follow each Next.
- '
- 'eg. For R0=1 To 100; Next R0 (FR0=1T100;NR0)
- '
- '-------------------------------------------
- 'Special registers
- '-------------------------------------------
- 'There are 3 special registers which can be used to set or test your objects
- 'status.
- '
- ' X (holds the objects X coordinate)
- ' Y (holds the objects Y coordinate)
- ' A (image number of the object)
- '
- 'Changing registers X and Y inside an Amal program will move your object
- 'around the screen:-
- '
- ' Let X=160;Let Y=Y+1 (LX=160;LY=Y+1)
- ' For R0=1 To 200;Let X=R0;Next R0 (FR0=1T200;LX=R0;NR0)
- '
- 'Changing the A register value will change the appearance of your object
- 'to the shape of that image number taken from the sprite bank, allowing
- 'complex and synchronised animations to take place.
- '
- 'eg. Let A=2
- ' For R5=1 To 10;Let A=R5;Next R5 (FR5=1T10;LA=R5;NR5)
- '
- '-------------------------------------------
- 'Amal If instruction
- '-------------------------------------------
- 'Keyword I
- '
- 'This is the Amal conditional test which allows control to be jumped to
- 'another part of your Amal program if the test is True (-1) otherwise Amal
- 'will continue with the next instruction.
- '
- 'eg. A: Let R0=20; B: Let R0=R0-1;Let X=R0;If R0<1 Jump B;Jump A
- '
- '-------------------------------------------
- 'Amal Pause instruction
- '-------------------------------------------
- 'Keyword P
- '
- 'Pause halts your Amal program until the next verticl blank and frees
- 'processor time for your Basic program. It is most frequently used before
- 'a Jump instruction to avoid over-stepping the maximum of 10 jumps per Vbl.
- 'This instruction if used wisely and can have a dramatic effect on the speed
- 'of your Basic program.
- '
- 'eg. A: Let X=X+1;Pause Jump A (A: LX=X+1;PJA)
- '
- '-------------------------------------------
- 'Amreg
- '-------------------------------------------
- 'This function allows access to the Amal registers from within your Basic
- 'program, values can be written to or read depending on the syntax used.
- '
- 'Reading a value from an external register:-
- '
- ' V=Amreg(0)
- '
- 'The number in brackets denotes which register is to be read and can be in
- 'the range of 0-25 representing the registers RA-RZ with 0=RA, 1=RB etc. etc.
- '
- 'Writing a value to an external register:-
- '
- ' Amreg(0)=V
- '
- 'The number in brackets once again denotes which register is to be accessed.
- '
- 'By adding an optional channel number the internal registers can be read:-
- '
- ' +--->channel number to be accessed
- ' | +--->register number 0-9 representing R0-R9
- ' V=Amreg(1,0)
- '
- 'A similar syntax is used to assign a value to the internal registers:-
- '
- ' Amreg(9,1)=V
- '
- '-------------------------------------------
- 'EXAMPLE
- '-------------------------------------------
- Auto View Off
- Rem *** load some objects to work with and clear the screen
- '
- Load "AmosPro_Tutorial:Objects/Amal_Bobs.abk"
- Screen Open 0,320,200,16,Lowres : Flash Off
- Get Sprite Palette : Curs Off : Cls 0 : Hide
- '
- Rem *** Amal program for moving both guns
- '
- A$="Label: Move142,0,142;Move -142,0,142;Pause Jump Label"
- '
- Rem *** Left gun fire uses external register RA (Amreg(0))
- '
- B$="Anim 0,(9,2)(10,2);LetRA=1;Move0,-200,25;LetRA=0"
- '
- Rem *** Right gun fire uses internal register R5 (Amreg(Channel,5))
- '
- C$="Anim 0,(9,2)(10,2);LetR5=1;Move0,-200,50;LetR5=0"
- '
- Rem *** set start positions of computed sprites
- '
- Sprite 8,128,218,11
- Sprite 9,282,218,11
- Sprite 10,0,218,9
- Sprite 11,0,218,9
- '
- Rem *** assign Amal channels to the strings
- Amal 10,B$
- Amal 11,C$
- Amal 8,A$
- '
- Rem *** start left gun moving
- '
- Amal On 8
- '
- Rem *** Print text
- '
- Paper 0 : Locate 0,3 : Centre "Press left mouse key to fire left gun"
- Pen 7 : Locate 0,6 : Centre "Press right mouse key to fire right gun"
- Pen 8 : Locate 0,9 : Centre "Press both to quit"
- '
- Rem *** short delay before starting right gun
- '
- Wait 60
- Amal 9,A$
- Amal On 9
- '
- Rem *** start the main basic loop to check the registers
- '
- View
- Do
- If Mouse Key=3 Then Direct
- If Amreg(0)=0 and Mouse Key=1 : Shoot
- Sprite 8,,,12 : Wait 4 : Sprite 8,,,11
- Sprite 10,X Sprite(8),206,9 : Amal 10,B$ : Amal On 10
- End If
- If Amreg(11,5)=0 and Mouse Key=2 : Boom
- Sprite 9,,,12 : Wait 4 : Sprite 9,,,11
- Sprite 11,X Sprite(9),206,9 : Amal 11,C$ : Amal On 11
- End If
- Wait 3
- Loop